//
// Created by 11510 on 2024/6/11.
//
#include <log4cpp/Category.hh>
#include <log4cpp/Appender.hh>
#include <log4cpp/OstreamAppender.hh>
#include <log4cpp/Layout.hh>
#include <log4cpp/BasicLayout.hh>
#include <log4cpp/Priority.hh>
#include <FileAppender.hh>
#include <log4cpp/PatternLayout.hh>
#include <iostream>
using namespace log4cpp;
using std::cout;
using std::endl;
int main() {
    /* 1. 设置布局 */
    PatternLayout *ptn1 = new PatternLayout();
    ptn1->setConversionPattern("%d %c [%p] %m%n");

    /* 2. 创建目的地对象 */
    OstreamAppender *pos = new OstreamAppender("console", &cout);
    pos->setLayout(ptn1);

    /**
     * 3. 创建记录器
     * 直接创建叶子会隐式创建root节点
     * Category &root = Category::getInstance("sub1");
     */
    Category &sales = Category::getRoot().getInstance("saleDepart");

    sales.setPriority(Priority::ERROR);
    sales.addAppender(pos);


    /* 4. 记录日志 */
    sales.emerg("this is an emerge msg");
    sales.fatal("this is a fatal msg");
    sales.alert("this is an alert msg");
    sales.crit("this is a crit msg");
    sales.error("this is an error msg");
    sales.warn("this is an warn msg");
    sales.notice("this is a notice msg");
    sales.info("this is a info msg");
    sales.debug("this is a debug msg");

    /* 5. 日志系统退出时候，回收资源 */
    Category::shutdown();

    return 0;
}
